// tower vessel
var g_towerVessel=null;
var TowerVessel = cc.Node.extend({
    _towerPa : null,
    ctor : function(){
        this._super();
        g_towerVessel=this;
        g_towerVessel.retain();
    },
    onEnter:function () {
        this._super();
        this.addTowerPa();
    },
    onExit : function(){
        this._super();
    },
    addTowerPa : function(){ // towers
        this._towerPa = new cc.Menu();
        this._towerPa.setPosition( cc.p(0,0) );
        this.addChild( this._towerPa );
    },
    //////////////////////////////////////////////////////////////
    addTower : function(data,pos){
        var tower = null;
        var filename = MainResource(data.res[0]);
        switch(data.type){
            case 0:{
                tower = TowerA.create( filename ,data );
                break;
            }
            case 1:{
                tower = TowerB.create( filename ,data );
                break;
            }
            case 2:{
                tower = TowerC.create( filename ,data );
                break;
            }
        }
        tower.setPosition( pos );
        tower.setUserData( data );
        tower.addPrice(data.su[0]);
        this._towerPa.addChild( tower );
        tower.setSeries(1);
        tower.setTarget(this.onTower,this._towerPa);
        cc.log("***tower number: "+this._towerPa.getChildren().length);
        //////////////////////////////////////////////////
        // register
        var jsonObj = GetMapObject();
        var point = PixelToPoint(jsonObj,pos);
        tower.setPoint( point );
        Register1(point,tower);

        var filename = AudioResource("land.mp3");
        cc.audioEngine.playEffect(filename);
    },
    onTower : function(sender){
        cc.log("on tower update");
        ShowUpdatePanel(sender);
    },
    ////////////////////////////////////
    getTowers : function(){
        return this._towerPa.getChildren();
    }
});
//////////////////////////////////////////////
AddTowerIntoTowerVessel=function(data,pos){
    g_towerVessel.addTower(data,pos);
}

